package com.cz.spb_minio.controller;

import com.cz.spb_minio.utils.MinioUtils;
import com.cz.spb_minio.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
public class FileUploadController {
    private Logger logger = LoggerFactory.getLogger(FileUploadController.class);

    @Autowired
    MinioUtils minioUtils;

    @PostMapping("minio/upload")
    public R uploadFile(HttpServletRequest req, MultipartFile file){
        HashMap<String, Object> map = new HashMap<>();
        String filePath = minioUtils.putObject(file);
        if(null!=filePath)
            logger.info("成功上传");
        return R.success(filePath);
    }
}
